﻿'Clinciu Andrei
Option Strict On

Imports System.Collections.Generic
Imports System.Data.OleDb

'This class is used for the Occasions.. it's easier than embedding code..
Public Class Occasion
    Private _id As Integer
    Private _name As String

    Public ReadOnly Property Name As String
        Get
            Return _name
        End Get
    End Property

    Public ReadOnly Property Id As Integer
        Get
            Return _id
        End Get
    End Property


    Public Sub New(ByVal id As Integer, ByVal name As String)
        _id = id
        _name = name
    End Sub

    '
    Public Shared Function SelectAllOccasions(ByRef dbh As DatabaseHelper) As List(Of Occasion)
        Dim theList As New List(Of Occasion)
        Dim reader As OleDbDataReader = dbh.GetReader("SELECT * FROM Gelegenheid", {})

        Do While reader.Read()
            Dim item As New Occasion(CInt(reader("GelegenheidID")), CStr(reader("GelegenheidNaam")))
            theList.Add(item)
        Loop

        reader.Close()

        Return theList
    End Function
    Public Shared Sub AddOccasion(ByRef dbh As DatabaseHelper, ByVal value As Occasion, Optional ByVal transaction As OleDbTransaction = Nothing)
        If transaction Is Nothing Then
            dbh.ExecuteSQL("INSERT INTO Gelegenheid (GelegenheidNaam) VALUES (?)", {value.Name}, True)
        Else
            dbh.ExecuteSQL("INSERT INTO Gelegenheid (GelegenheidNaam) VALUES (?)", {value.Name}, transaction)
        End If


    End Sub
    Public Overrides Function toString() As String
        Return _name
    End Function
End Class
